package set.test;

import java.util.Iterator;
import java.util.TreeSet;
import java.util.function.Consumer;

public class TreeSetDemo {
    public static void main(String[] args) {
        //1.创建集合
        TreeSet<Integer> ts = new TreeSet<>();
        //2.添加对象
        ts.add(1);
        ts.add(3);
        ts.add(5);
        ts.add(2);
        ts.add(4);
        //3.打印集合 会自动排序
        System.out.println(ts);

        //4. 迭代器遍历
        Iterator<Integer> it = ts.iterator();
        while (it.hasNext()) {
            Integer i = it.next();
            System.out.println(i);
        }
        //4.2 增强for
        for (Integer t : ts) {
            System.out.println(t);
        }
        //4.3 lamdba
      /*  ts.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });*/
        ts.forEach(integer -> System.out.println(integer));

    }
}
